import tkinter as tk
from tkinter import messagebox, StringVar
import pymssql
import pymysql
import PIL
import pandas as pd
from tkinter import messagebox
import pymysql
from tkinter import *
import csv


################################################################################################/数据库操作/
# 供应商部分
def add_gys():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 供应商表(供应商编号,供应商名称,供应商简称,地址,公司电话,邮件,联系人,联系人电话,备注) values('%s','%s','%s','%s','%s','%s','%s','%s','%s')" % (
        s1.get(), s2.get(), s3.get(), s4.get(), s5.get(), s6.get(), s7.get(), s8.get(), s9.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def select_gys():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "select * from 供应商表"
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        result = cursor.fetchall()  # 获取查询结果
        connect.commit()
        show_result(result)  # 显示查询结果
    except Exception as e:
        print(f"查询出错: {e}")
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def show_result(result):
    for idx, row in enumerate(result):
        for col_idx, value in enumerate(row):
            label = tk.Label(window_function, text=value)
            label.grid(row=idx+1, column=col_idx)


def search_gys():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    product_id = entry_bh.get()
    query = "SELECT * FROM 供应商表 WHERE 供应商编号 = %s"
    cursor.execute(query, (product_id,))
    result = cursor.fetchone()
    if result:
        entry_name.delete(0, tk.END)
        entry_name.insert(0, result[1])
        entry_jc.delete(0, tk.END)
        entry_jc.insert(0, result[2])
        entry_dz.delete(0, tk.END)
        entry_dz.insert(0, result[3])
        entry_gsdh.delete(0, tk.END)
        entry_gsdh.insert(0, result[4])
        entry_yj.delete(0, tk.END)
        entry_yj.insert(0, result[5])
        entry_lxr.delete(0, tk.END)
        entry_lxr.insert(0, result[6])
        entry_lxrdh.delete(0, tk.END)
        entry_lxrdh.insert(0, result[7])
        entry_bz.delete(0, tk.END)
        entry_bz.insert(0, result[8])
    else:
        label_result.config(text="未找到该供应商编号！")


def update_gys():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()

    name = entry_name.get()
    jc = entry_jc.get()
    dz = entry_dz.get()
    gsdh = entry_gsdh.get()
    yj = entry_yj.get()
    lxr = entry_lxr.get()
    lxrdh = entry_lxrdh.get()
    bz = entry_bz.get()
    bh = entry_bh.get()
    query = "UPDATE 供应商表 SET 供应商名称=%s,供应商简称=%s, 地址=%s, 公司电话=%s, 邮件=%s, 联系人=%s, 联系人电话=%s, 备注=%s WHERE 供应商编号 = %s"
    cursor.execute(query, (name, jc, dz, gsdh, yj, lxr, lxrdh, bz, bh))
    connect.commit()
    label_result.config(text="商品信息已更新！")


def delete_gys():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 供应商表 where 供应商编号='%s'" % (s1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 员工部分
def add_yg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 员工表(员工编号,员工姓名,员工密码,员工级别,员工电话,员工工资,备注) values('%s','%s','%s','%s','%s','%s','%s')" % (
    s1.get(), s2.get(), s3.get(), s4.get(), s5.get(), s6.get(), s7.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def select_yg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "select * from 员工表"
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        result = cursor.fetchall()  # 获取查询结果
        connect.commit()
        show_result(result)  # 显示查询结果
    except Exception as e:
        print(f"查询出错: {e}")
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def search_yg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    product_id = entry_bh.get()
    query = "SELECT * FROM 员工表 WHERE 员工编号 = %s"
    cursor.execute(query, (product_id,))
    result = cursor.fetchone()
    if result:
        entry_name.delete(0, tk.END)
        entry_name.insert(0, result[1])
        entry_mm.delete(0, tk.END)
        entry_mm.insert(0, result[2])
        entry_jb.delete(0, tk.END)
        entry_jb.insert(0, result[3])
        entry_dh.delete(0, tk.END)
        entry_dh.insert(0, result[4])
        entry_gz.delete(0, tk.END)
        entry_gz.insert(0, result[5])
        entry_bz.delete(0, tk.END)
        entry_bz.insert(0, result[6])
    else:
        label_result.config(text="未找到该员工编号！")


def update_yg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()

    name = entry_name.get()
    mm = entry_mm.get()
    jb = entry_jb.get()
    dh = entry_dh.get()
    gz = entry_gz.get()
    bz = entry_bz.get()
    bh = entry_bh.get()
    query = "UPDATE 员工表 SET 员工姓名=%s, 员工密码=%s, 员工级别=%s, 员工电话=%s, 员工工资=%s, 备注=%s WHERE 员工编号 = %s"
    cursor.execute(query, (name, mm, jb, dh, gz, bz, bh))
    connect.commit()
    label_result.config(text="员工信息已更新！")


def delete_yg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 员工表 where 员工编号='%s'" % (s1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 商品部分
def add_sp():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 商品表(商品编号,商品名称,商品单价,供应商编号,商品简介,备注) values('%s','%s','%s','%s','%s','%s')" % (
    s1.get(), s2.get(), s3.get(), s4.get(), s5.get(), s6.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def select_sp():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "select * from 商品表"
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        result = cursor.fetchall()  # 获取查询结果
        connect.commit()
        show_result(result)  # 显示查询结果
    except Exception as e:
        print(f"查询出错: {e}")
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def search_sp():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    product_id = entry_bh.get()
    query = "SELECT * FROM 商品表 WHERE 商品编号 = %s"
    cursor.execute(query, (product_id,))
    result = cursor.fetchone()
    if result:
        entry_name.delete(0, tk.END)
        entry_name.insert(0, result[1])
        entry_dj.delete(0, tk.END)
        entry_dj.insert(0, result[2])
        entry_gysbh.delete(0, tk.END)
        entry_gysbh.insert(0, result[3])
        entry_jj.delete(0, tk.END)
        entry_jj.insert(0, result[4])
        entry_bz.delete(0, tk.END)
        entry_bz.insert(0, result[5])
    else:
        label_result.config(text="未找到该商品编号！")


def update_sp():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()

    name = entry_name.get()
    dj = entry_dj.get()
    gysbh = entry_gysbh.get()
    jj = entry_jj.get()
    bz = entry_bz.get()
    bh = entry_bh.get()
    query = "UPDATE 商品表 SET 商品名称=%s, 商品单价=%s, 供应商编号=%s, 商品简介=%s, 备注=%s WHERE 商品编号 = %s"
    cursor.execute(query, (name, dj, gysbh, jj, bz, bh))
    connect.commit()
    label_result.config(text="商品信息已更新！")


def delete_sp():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 商品表 where 商品编号='%s'" % (s1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


# 采购部分
def add_cgzb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 采购主表(采购清单号,员工编号,采购数量,采购总价,采购时间,备注) values('%s','%s','%s','%s','%s','%s')" % (
    s1.get(), s2.get(), s3.get(), s4.get(), s5.get(), s6.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def add_cgmxb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 采购明细表(采购明细号,采购清单号,商品编号,采购数量,商品单价,商品总价,备注) values('%s','%s','%s','%s','%s','%s','%s')" % (
    s1.get(), s2.get(), s3.get(), s4.get(), s5.get(), s6.get(), s7.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def select_cgzb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "select * from 采购主表"
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        result = cursor.fetchall()  # 获取查询结果
        connect.commit()
        show_result(result)  # 显示查询结果
    except Exception as e:
        print(f"查询出错: {e}")
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def select_cgmxb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "select * from 采购明细表"
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        result = cursor.fetchall()  # 获取查询结果
        connect.commit()
        show_result(result)  # 显示查询结果
    except Exception as e:
        print(f"查询出错: {e}")
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def search_cgzb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    product_id = entry_qdh.get()
    query = "SELECT * FROM 采购主表 WHERE 采购清单号 = %s"
    cursor.execute(query, (product_id,))
    result = cursor.fetchone()
    if result:
        entry_ygbh.delete(0, tk.END)
        entry_ygbh.insert(0, result[1])
        entry_sl.delete(0, tk.END)
        entry_sl.insert(0, result[2])
        entry_zj.delete(0, tk.END)
        entry_zj.insert(0, result[3])
        entry_sj.delete(0, tk.END)
        entry_sj.insert(0, result[4])
        entry_bz.delete(0, tk.END)
        entry_bz.insert(0, result[5])
    else:
        label_result.config(text="未找到该采购清单号！")


def update_cgzb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()

    ygbh = entry_ygbh.get()
    sl = entry_sl.get()
    zj = entry_zj.get()
    sj = entry_sj.get()
    bz = entry_bz.get()
    qdh = entry_qdh.get()
    query = "UPDATE 采购主表 SET 员工编号=%s, 采购数量=%s, 采购总价=%s, 采购时间=%s, 备注=%s WHERE 采购清单号 = %s"
    cursor.execute(query, (ygbh, sl, zj, sj, bz, qdh))
    connect.commit()
    label_result.config(text="采购主表信息已更新！")


def search_cgmxb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    product_id = entry_mxh.get()
    query = "SELECT * FROM 采购明细表 WHERE 采购明细号 = %s"
    cursor.execute(query, (product_id,))
    result = cursor.fetchone()
    if result:
        entry_qdh.delete(0, tk.END)
        entry_qdh.insert(0, result[1])
        entry_spbh.delete(0, tk.END)
        entry_spbh.insert(0, result[2])
        entry_sl.delete(0, tk.END)
        entry_sl.insert(0, result[3])
        entry_dj.delete(0, tk.END)
        entry_dj.insert(0, result[4])
        entry_zj.delete(0, tk.END)
        entry_zj.insert(0, result[5])
        entry_bz.delete(0, tk.END)
        entry_bz.insert(0, result[6])
    else:
        label_result.config(text="未找到该采购明细号！")


def update_cgmxb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()

    qdh = entry_qdh.get()
    spbh = entry_spbh.get()
    sl = entry_sl.get()
    dj = entry_dj.get()
    zj = entry_zj.get()
    bz = entry_bz.get()
    mxh = entry_mxh.get()
    query = "UPDATE 采购明细表 SET 采购清单号=%s, 商品编号=%s, 采购数量=%s, 商品单价=%s, 商品总价=%s, 备注=%s WHERE 采购明细号 = %s"
    cursor.execute(query, (qdh, spbh, sl, dj, zj, bz, mxh))
    connect.commit()
    label_result.config(text="采购明细表信息已更新！")


def delete_cgzb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 采购主表 where 采购清单号='%s'" % (s1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


def delete_cgmxb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 采购明细表 where 采购明细号='%s'" % (s1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()


###########################################################################################################/供应商/
def add_customer():  # 添加供应商界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1, s2, s3, s4, s5, s6, s7, s8, s9
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("添加供应商信息")
    # 窗口大小
    window_function.geometry('400x600')

    # 生成标签
    tk.Label(window_function, text="添加新供应商", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function, text="请输入供应商编号：").grid(row=1, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入供应商名称：").grid(row=2, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入供应商简称：").grid(row=3, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入地址：").grid(row=4, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入公司电话：").grid(row=5, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入邮件：").grid(row=6, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入联系人：").grid(row=7, column=0, padx=20, pady=10)
    tk.Label(window_function, text="请输入联系人电话：").grid(row=8, column=0, padx=20, pady=10)
    tk.Label(window_function, text="备注：").grid(row=9, column=0, padx=20, pady=10)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    s2 = tk.StringVar()
    s3 = tk.StringVar()
    s4 = tk.StringVar()
    s5 = tk.StringVar()
    s6 = tk.StringVar()
    s7 = tk.StringVar()
    s8 = tk.StringVar()
    s9 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function, show=None, textvariable=s2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=s3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function, show=None, textvariable=s4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function, show=None, textvariable=s5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function, show=None, textvariable=s6).grid(row=6, column=1)
    entry7 = tk.Entry(window_function, show=None, textvariable=s7).grid(row=7, column=1)
    entry8 = tk.Entry(window_function, show=None, textvariable=s8).grid(row=8, column=1)
    entry9 = tk.Entry(window_function, show=None, textvariable=s9).grid(row=9, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="添加", command=add_gys).place(relx=0.3, rely=0.875)
    button2 = tk.Button(window_function, text="返回", command=back1_to_change_customer).place(relx=0.5, rely=0.875)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def select_customer():  # 查询供应商界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("供应商信息")
    # 显示标题文字
    title_label = tk.Label(window_function,
                           text="供应商编号" + " "*19 + "供应商名称"+" "*19 + "供应商简称"+" "*26 + "地址"+" "*30 + "公司电话"+" "*20 + "邮件" + " "*29 + "联系人"+" "*13 + "联系人电话"+" "*10 + "备注")
    title_label.grid(row=0, column=0, columnspan=9)
    # 窗口大小
    window_function.geometry('900x500')
    select_gys()
    button1 = tk.Button(window_function, text="返回", command=back2_to_change_customer).place(relx=0.3, rely=0.8)
    # 显示窗口
    button2 = tk.Button(window_function, text="导出", command=export_customer_data).place(relx=0.5, rely=0.8)

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def update_customer():  # 更新供应商界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global entry_bh, entry_name, entry_jc, entry_dz, entry_gsdh, entry_yj, entry_lxr, entry_lxrdh, entry_bz, label_result

    # 创建GUI界面
    window_function = tk.Tk()
    window_function.title("供应商信息管理")
    window_function.geometry('400x600')
    label_bh = tk.Label(window_function, text="供应商编号：")
    label_bh.pack()
    entry_bh = tk.Entry(window_function)
    entry_bh.pack()

    button_search = tk.Button(window_function, text="查询", command=search_gys)
    button_search.pack()

    label_name = tk.Label(window_function, text="供应商名称：")
    label_name.pack()
    entry_name = tk.Entry(window_function)
    entry_name.pack()

    label_jc = tk.Label(window_function, text="供应商简称：")
    label_jc.pack()
    entry_jc = tk.Entry(window_function)
    entry_jc.pack()

    label_dz = tk.Label(window_function, text="地址：")
    label_dz.pack()
    entry_dz = tk.Entry(window_function)
    entry_dz.pack()

    label_gsdh = tk.Label(window_function, text="公司电话：")
    label_gsdh.pack()
    entry_gsdh = tk.Entry(window_function)
    entry_gsdh.pack()

    label_yj = tk.Label(window_function, text="邮件：")
    label_yj.pack()
    entry_yj = tk.Entry(window_function)
    entry_yj.pack()

    label_lxr = tk.Label(window_function, text="联系人：")
    label_lxr.pack()
    entry_lxr = tk.Entry(window_function)
    entry_lxr.pack()

    label_lxrdh = tk.Label(window_function, text="联系人电话：")
    label_lxrdh.pack()
    entry_lxrdh = tk.Entry(window_function)
    entry_lxrdh.pack()

    label_bz = tk.Label(window_function, text="备注：")
    label_bz.pack()
    entry_bz = tk.Entry(window_function)
    entry_bz.pack()

    button_update = tk.Button(window_function, text="保存", command=update_gys).place(relx=0.3, rely=0.8)
    button_back = tk.Button(window_function, text="返回", command=back3_to_change_customer).place(relx=0.5, rely=0.8)

    label_result = tk.Label(window_function, text="")
    label_result.pack()

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def delete_customer():  # 删除供应商界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("删除供应商信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="请输入供应商编号：").grid(row=1, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="确认", command=delete_gys).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back4_to_change_customer).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def back1_to_change_customer():
    window_function.destroy()
    customer()


def back2_to_change_customer():
    window_function.destroy()
    customer()


def back3_to_change_customer():
    window_function.destroy()
    customer()


def back4_to_change_customer():
    window_function.destroy()
    customer()


def customer():
    global window_choice
    window_choice = tk.Tk()
    window_choice.title("供应商管理界面")
    window_choice.geometry('400x300')
    button1 = tk.Button(window_choice, text="增加供应商", command=add_customer).pack(pady=10)
    button2 = tk.Button(window_choice, text="查看供应商", command=select_customer).pack(pady=10)
    button3 = tk.Button(window_choice, text="修改供应商", command=update_customer).pack(pady=10)
    button4 = tk.Button(window_choice, text="删除供应商", command=delete_customer).pack(pady=10)
    button5 = tk.Button(window_choice, text="返回", command=change_window).pack(pady=10)

    # 计算窗口居中的位置
    window_choice.update_idletasks()
    width = window_choice.winfo_width()
    height = window_choice.winfo_height()
    screenwidth = window_choice.winfo_screenwidth()
    screenheight = window_choice.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_choice.geometry('+{}+{}'.format(x, y))

    window_choice.mainloop()


####################################################################################################/员工/
def add_employee():  # 添加员工界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1, s2, s3, s4, s5, s6, s7
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("添加员工信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="添加新员工", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function, text="请输入员工编号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工姓名：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工密码：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工级别：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工电话：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工资：").grid(row=6, column=0, padx=20, pady=20)
    tk.Label(window_function, text="备注：").grid(row=7, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    s2 = tk.StringVar()
    s3 = tk.StringVar()
    s4 = tk.StringVar()
    s5 = tk.StringVar()
    s6 = tk.StringVar()
    s7 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function, show=None, textvariable=s2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=s3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function, show=None, textvariable=s4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function, show=None, textvariable=s5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function, show=None, textvariable=s6).grid(row=6, column=1)
    entry7 = tk.Entry(window_function, show=None, textvariable=s7).grid(row=7, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="添加", command=add_yg).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back1_to_change_employee).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def select_employee():  # 查询员工界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("员工信息")
    # 显示标题文字
    title_label = tk.Label(window_function, text="员工编号    员工姓名      员工密码      员工级别     员工电话      员工工资  备注")
    title_label.grid(row=0, column=0, columnspan=7)
    # 窗口大小
    window_function.geometry('700x500')
    select_yg()
    button1 = tk.Button(window_function, text="返回", command=back2_to_change_employee).place(relx=0.3, rely=0.8)
    # 显示窗口
    button2 = tk.Button(window_function, text="导出", command=export_employee_data).place(relx=0.5, rely=0.8)

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def update_employee():  # 更新员工界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global entry_bh, entry_name, entry_mm, entry_jb, entry_dh, entry_gz, entry_bz, label_result

    # 创建GUI界面
    window_function = tk.Tk()
    window_function.title("员工信息管理")
    window_function.geometry('400x600')
    label_bh = tk.Label(window_function, text="员工编号：")
    label_bh.pack()
    entry_bh = tk.Entry(window_function)
    entry_bh.pack()

    button_search = tk.Button(window_function, text="查询", command=search_yg)
    button_search.pack()

    label_name = tk.Label(window_function, text="员工姓名：")
    label_name.pack()
    entry_name = tk.Entry(window_function)
    entry_name.pack()

    label_mm = tk.Label(window_function, text="员工密码：")
    label_mm.pack()
    entry_mm = tk.Entry(window_function)
    entry_mm.pack()

    label_jb = tk.Label(window_function, text="员工级别：")
    label_jb.pack()
    entry_jb = tk.Entry(window_function)
    entry_jb.pack()

    label_dh = tk.Label(window_function, text="员工电话：")
    label_dh.pack()
    entry_dh = tk.Entry(window_function)
    entry_dh.pack()

    label_gz = tk.Label(window_function, text="员工工资：")
    label_gz.pack()
    entry_gz = tk.Entry(window_function)
    entry_gz.pack()

    label_bz = tk.Label(window_function, text="备注：")
    label_bz.pack()
    entry_bz = tk.Entry(window_function)
    entry_bz.pack()

    button_update = tk.Button(window_function, text="保存", command=update_yg).place(relx=0.3, rely=0.8)
    button_back = tk.Button(window_function, text="返回", command=back3_to_change_employee).place(relx=0.5, rely=0.8)

    label_result = tk.Label(window_function, text="")
    label_result.pack()

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def delete_employee():  # 删除员工界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("删除员工信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="请输入员工编号：").grid(row=1, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="确认", command=delete_yg).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back4_to_change_employee).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def back1_to_change_employee():
    window_function.destroy()
    employee()


def back2_to_change_employee():
    window_function.destroy()
    employee()


def back3_to_change_employee():
    window_function.destroy()
    employee()


def back4_to_change_employee():
    window_function.destroy()
    employee()


def employee():
    global window_choice
    window_choice = tk.Tk()
    window_choice.title("员工管理界面")
    window_choice.geometry('400x300')
    button1 = tk.Button(window_choice, text="增加员工信息", command=add_employee).pack(pady=10)
    button2 = tk.Button(window_choice, text="查看员工信息", command=select_employee).pack(pady=10)
    button3 = tk.Button(window_choice, text="修改员工信息", command=update_employee).pack(pady=10)
    button4 = tk.Button(window_choice, text="删除员工信息", command=delete_employee).pack(pady=10)
    button5 = tk.Button(window_choice, text="返回", command=change_window).pack(pady=10)

    # 计算窗口居中的位置
    window_choice.update_idletasks()
    width = window_choice.winfo_width()
    height = window_choice.winfo_height()
    screenwidth = window_choice.winfo_screenwidth()
    screenheight = window_choice.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_choice.geometry('+{}+{}'.format(x, y))

    window_choice.mainloop()


####################################################################################################/商品/
def add_good():  # 添加商品界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1, s2, s3, s4, s5, s6
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("添加商品信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="添加新商品", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function, text="请输入商品编号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品名称：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品单价：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入供应商编号：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品简介：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function, text="备注：").grid(row=6, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    s2 = tk.StringVar()
    s3 = tk.StringVar()
    s4 = tk.StringVar()
    s5 = tk.StringVar()
    s6 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function, show=None, textvariable=s2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=s3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function, show=None, textvariable=s4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function, show=None, textvariable=s5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function, show=None, textvariable=s6).grid(row=6, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="添加", command=add_sp).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back1_to_change_good).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def select_good():  # 查询商品界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("商品信息")
    # 显示标题文字
    title_label = tk.Label(window_function, text="商品编号      商品名称  商品单价  供应商编号  商品简介      备注")
    title_label.grid(row=0, column=0, columnspan=6)
    # 窗口大小
    window_function.geometry('700x700')
    select_sp()
    button1 = tk.Button(window_function, text="返回", command=back2_to_change_good).place(relx=0.3, rely=0.8)
    # 显示窗口
    button2 = tk.Button(window_function, text="导出", command=export_good_data).place(relx=0.5, rely=0.8)

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def update_good():  # 更新商品界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global entry_bh, entry_name, entry_dj, entry_gysbh, entry_jj, entry_bz, label_result

    # 创建GUI界面
    window_function = tk.Tk()
    window_function.title("商品信息管理")
    window_function.geometry('400x600')
    label_bh = tk.Label(window_function, text="商品编号：")
    label_bh.pack()
    entry_bh = tk.Entry(window_function)
    entry_bh.pack()

    button_search = tk.Button(window_function, text="查询", command=search_sp)
    button_search.pack()

    label_name = tk.Label(window_function, text="供应商名称：")
    label_name.pack()
    entry_name = tk.Entry(window_function)
    entry_name.pack()

    label_dj = tk.Label(window_function, text="商品单价：")
    label_dj.pack()
    entry_dj = tk.Entry(window_function)
    entry_dj.pack()

    label_gysbh = tk.Label(window_function, text="供应商编号：")
    label_gysbh.pack()
    entry_gysbh = tk.Entry(window_function)
    entry_gysbh.pack()

    label_jj = tk.Label(window_function, text="商品简介：")
    label_jj.pack()
    entry_jj = tk.Entry(window_function)
    entry_jj.pack()

    label_bz = tk.Label(window_function, text="备注：")
    label_bz.pack()
    entry_bz = tk.Entry(window_function)
    entry_bz.pack()

    button_update = tk.Button(window_function, text="保存", command=update_sp).place(relx=0.3, rely=0.8)
    button_back = tk.Button(window_function, text="返回", command=back3_to_change_good).place(relx=0.5, rely=0.8)

    label_result = tk.Label(window_function, text="")
    label_result.pack()

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def delete_good():  # 删除商品界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("删除商品信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="请输入商品编号：").grid(row=1, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="确认", command=delete_sp).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back4_to_change_good).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def back1_to_change_good():
    window_function.destroy()
    good()


def back2_to_change_good():
    window_function.destroy()
    good()


def back3_to_change_good():
    window_function.destroy()
    good()


def back4_to_change_good():
    window_function.destroy()
    good()


def good():
    global window_choice
    window_choice = tk.Tk()
    window_choice.title("商品管理界面")
    window_choice.geometry('400x300')
    button1 = tk.Button(window_choice, text="增加商品信息", command=add_good).pack(pady=10)
    button2 = tk.Button(window_choice, text="查看商品信息", command=select_good).pack(pady=10)
    button3 = tk.Button(window_choice, text="修改商品信息", command=update_good).pack(pady=10)
    button4 = tk.Button(window_choice, text="删除商品信息", command=delete_good).pack(pady=10)
    button5 = tk.Button(window_choice, text="返回", command=change_window).pack(pady=10)

    # 计算窗口居中的位置
    window_choice.update_idletasks()
    width = window_choice.winfo_width()
    height = window_choice.winfo_height()
    screenwidth = window_choice.winfo_screenwidth()
    screenheight = window_choice.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_choice.geometry('+{}+{}'.format(x, y))

    window_choice.mainloop()


##############################################################################################/采购管理/
def add_pay_main():  # 添加采购主表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1, s2, s3, s4, s5, s6
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("添加采购主表信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="添加新信息", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function, text="请输入采购清单号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工编号：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入采购数量：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入采购总价：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入采购时间：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function, text="备注：").grid(row=6, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    s2 = tk.StringVar()
    s3 = tk.StringVar()
    s4 = tk.StringVar()
    s5 = tk.StringVar()
    s6 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function, show=None, textvariable=s2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=s3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function, show=None, textvariable=s4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function, show=None, textvariable=s5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function, show=None, textvariable=s6).grid(row=6, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="添加", command=add_cgzb).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back1_to_change_buy).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def add_pay_detail():  # 添加采购明细表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1, s2, s3, s4, s5, s6, s7
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("添加采购明细表信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="添加新信息", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function, text="请输入采购明细号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入采购清单：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品编号：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入采购数量：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品单价：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入商品总价：").grid(row=6, column=0, padx=20, pady=20)
    tk.Label(window_function, text="备注：").grid(row=7, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    s2 = tk.StringVar()
    s3 = tk.StringVar()
    s4 = tk.StringVar()
    s5 = tk.StringVar()
    s6 = tk.StringVar()
    s7 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function, show=None, textvariable=s2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=s3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function, show=None, textvariable=s4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function, show=None, textvariable=s5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function, show=None, textvariable=s6).grid(row=6, column=1)
    entry6 = tk.Entry(window_function, show=None, textvariable=s7).grid(row=7, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="添加", command=add_cgmxb).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back2_to_change_buy).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def select_pay_main():  # 查询采购主表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("采购主表信息")
    # 显示标题文字
    title_label = tk.Label(window_function, text="采购清单号  员工编号  采购数量  采购总价  采购时间  备注")
    title_label.grid(row=0, column=0, columnspan=6)
    # 窗口大小
    window_function.geometry('400x700')
    select_cgzb()
    button1 = tk.Button(window_function, text="返回", command=back3_to_change_buy).place(relx=0.3, rely=0.8)
    # 显示窗口
    button2 = tk.Button(window_function, text="导出", command=export_pay_main_data).place(relx=0.5, rely=0.8)

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def select_pay_detail():  # 查询采购明细界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("采购明细信息")
    # 显示标题文字
    title_label = tk.Label(window_function, text="  采购明细号  采购清单号    商品编号    采购数量  商品单价  商品总价  备注")
    title_label.grid(row=0, column=0, columnspan=7)
    # 窗口大小
    window_function.geometry('500x700')
    select_cgmxb()
    button1 = tk.Button(window_function, text="返回", command=back4_to_change_buy).place(relx=0.3, rely=0.8)
    # 显示窗口
    button2 = tk.Button(window_function, text="导出", command=export_pay_detail_data).place(relx=0.5, rely=0.8)

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def update_pay_main():  # 更新采购主表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global entry_qdh, entry_ygbh, entry_sl, entry_zj, entry_sj, entry_bz, label_result

    # 创建GUI界面
    window_function = tk.Tk()
    window_function.title("采购主表信息管理")
    window_function.geometry('400x600')
    label_qdh = tk.Label(window_function, text="采购清单号：")
    label_qdh.pack()
    entry_qdh = tk.Entry(window_function)
    entry_qdh.pack()

    button_search = tk.Button(window_function, text="查询", command=search_cgzb)
    button_search.pack()

    label_ygbh = tk.Label(window_function, text="员工编号：")
    label_ygbh.pack()
    entry_ygbh = tk.Entry(window_function)
    entry_ygbh.pack()

    label_sl = tk.Label(window_function, text="采购数量：")
    label_sl.pack()
    entry_sl = tk.Entry(window_function)
    entry_sl.pack()

    label_zj = tk.Label(window_function, text="采购总价：")
    label_zj.pack()
    entry_zj = tk.Entry(window_function)
    entry_zj.pack()

    label_sj = tk.Label(window_function, text="采购时间：")
    label_sj.pack()
    entry_sj = tk.Entry(window_function)
    entry_sj.pack()

    label_bz = tk.Label(window_function, text="备注：")
    label_bz.pack()
    entry_bz = tk.Entry(window_function)
    entry_bz.pack()

    button_update = tk.Button(window_function, text="保存", command=update_cgzb).place(relx=0.3, rely=0.8)
    button_back = tk.Button(window_function, text="返回", command=back5_to_change_buy).place(relx=0.5, rely=0.8)

    label_result = tk.Label(window_function, text="")
    label_result.pack()

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def update_pay_detail():  # 更新采购明细界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global entry_mxh, entry_qdh, entry_spbh, entry_sl, entry_dj, entry_zj, entry_bz, label_result

    # 创建GUI界面
    window_function = tk.Tk()
    window_function.title("采购明细表信息管理")
    window_function.geometry('400x600')
    label_mxh = tk.Label(window_function, text="采购明细号：")
    label_mxh.pack()
    entry_mxh = tk.Entry(window_function)
    entry_mxh.pack()

    button_search = tk.Button(window_function, text="查询", command=search_cgmxb)
    button_search.pack()

    label_qdh = tk.Label(window_function, text="采购清单号：")
    label_qdh.pack()
    entry_qdh = tk.Entry(window_function)
    entry_qdh.pack()

    label_spbh = tk.Label(window_function, text="商品编号：")
    label_spbh.pack()
    entry_spbh = tk.Entry(window_function)
    entry_spbh.pack()

    label_sl = tk.Label(window_function, text="采购数量：")
    label_sl.pack()
    entry_sl = tk.Entry(window_function)
    entry_sl.pack()

    label_dj = tk.Label(window_function, text="商品单价：")
    label_dj.pack()
    entry_dj = tk.Entry(window_function)
    entry_dj.pack()

    label_zj = tk.Label(window_function, text="商品总价：")
    label_zj.pack()
    entry_zj = tk.Entry(window_function)
    entry_zj.pack()

    label_bz = tk.Label(window_function, text="备注：")
    label_bz.pack()
    entry_bz = tk.Entry(window_function)
    entry_bz.pack()

    button_update = tk.Button(window_function, text="保存", command=update_cgmxb).place(relx=0.3, rely=0.8)
    button_back = tk.Button(window_function, text="返回", command=back6_to_change_buy).place(relx=0.5, rely=0.8)

    label_result = tk.Label(window_function, text="")
    label_result.pack()

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def delete_pay_main():  # 删除采购主表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("删除采购主表信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="请输入采购清单号：").grid(row=1, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="确认", command=delete_cgzb).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back7_to_change_buy).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def delete_pay_detail():  # 删除采购明细表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("删除采购明细表信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="请输入采购明细号：").grid(row=1, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="确认", command=delete_cgmxb).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back8_to_change_buy).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def back1_to_change_buy():
    window_function.destroy()
    buy()


def back2_to_change_buy():
    window_function.destroy()
    buy()


def back3_to_change_buy():
    window_function.destroy()
    buy()


def back4_to_change_buy():
    window_function.destroy()
    buy()


def back5_to_change_buy():
    window_function.destroy()
    buy()


def back6_to_change_buy():
    window_function.destroy()
    buy()


def back7_to_change_buy():
    window_function.destroy()
    buy()


def back8_to_change_buy():
    window_function.destroy()
    buy()


def buy():
    global window_choice
    window_choice = tk.Tk()
    window_choice.title("采购管理界面")
    window_choice.geometry('400x500')
    button1 = tk.Button(window_choice, text="增加采购主表数据", command=add_pay_main).pack(pady=10)
    button2 = tk.Button(window_choice, text="增加采购明细表数据", command=add_pay_detail).pack(pady=10)
    button3 = tk.Button(window_choice, text="查询采购主表数据", command=select_pay_main).pack(pady=10)
    button3 = tk.Button(window_choice, text="查询采购明细表数据", command=select_pay_detail).pack(pady=10)
    button3 = tk.Button(window_choice, text="修改采购主表数据", command=update_pay_main).pack(pady=10)
    button3 = tk.Button(window_choice, text="修改采购明细表数据", command=update_pay_detail).pack(pady=10)
    button4 = tk.Button(window_choice, text="删除采购主表数据", command=delete_pay_main).pack(pady=10)
    button4 = tk.Button(window_choice, text="删除采购明细表数据", command=delete_pay_detail).pack(pady=10)
    button5 = tk.Button(window_choice, text="返回", command=change_window).pack(pady=10)

    # 计算窗口居中的位置
    window_choice.update_idletasks()
    width = window_choice.winfo_width()
    height = window_choice.winfo_height()
    screenwidth = window_choice.winfo_screenwidth()
    screenheight = window_choice.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_choice.geometry('+{}+{}'.format(x, y))

    window_choice.mainloop()


#####################################################一些跳转
#####################################################
#####################################################
def change_customer():
    window.destroy()
    customer()


def change_employee():
    window.destroy()
    employee()


def change_good():
    window.destroy()
    good()


def change_buy():
    window.destroy()
    buy()


def change_window():
    window_choice.destroy()
    mainpage()


# 返回登录界面
def change_login():
    window.destroy()
    login_page()


#################################################################################################/登录界面和主页面/

import tkinter as tk
from tkinter import messagebox


# 创建登录界面
def login_page():
    global root, id_entry, password_entry, level_entry
    root = tk.Tk()
    root.title("用户登录")
    root.geometry('400x200')

    tk.Label(root, text="编号：").grid(row=0, column=0, padx=20, pady=10)
    id_entry = tk.Entry(root)
    id_entry.grid(row=0, column=1)

    tk.Label(root, text="密码：").grid(row=1, column=0, padx=20, pady=10)
    password_entry = tk.Entry(root, show="*")
    password_entry.grid(row=1, column=1)

    tk.Label(root, text="级别：").grid(row=2, column=0, padx=20, pady=10)
    level_entry = tk.Entry(root)
    level_entry.grid(row=2, column=1)

    login_button = tk.Button(root, text="登录",
                             command=lambda: submit(id_entry.get(), password_entry.get(), level_entry.get()))
    login_button.place(relx=0.5, rely=0.7)

    # 计算窗口居中的位置
    root.update_idletasks()
    width = root.winfo_width()
    height = root.winfo_height()
    screenwidth = root.winfo_screenwidth()
    screenheight = root.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    root.geometry('+{}+{}'.format(x, y))

    root.mainloop()


def submit(input_id, input_password, input_level):
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    cursor = connect.cursor()

    sql = "SELECT * FROM 员工表"
    global ygbh

    try:
        cursor.execute(sql)
        employees = cursor.fetchall()
        input_list = [str(input_id), str(input_password), str(input_level)]  # 用户输入的列表
        employee_data_list = []
        ygbh = str(input_id)
        for employee in employees:
            employee_data_list = ([employee[0], employee[2], employee[3]])
            if input_list == employee_data_list:
                if input_list[2] == "20":  # 判断是否为管理员
                    messagebox.showinfo("登录成功", "管理员登录成功")
                    root.destroy()  # 关闭登录界面
                    mainpage()
                else:
                    messagebox.showinfo("登录成功", "普通用户登录成功")
                    root.destroy()  # 关闭登录界面
                    employee_page()
                return

        messagebox.showerror("登录失败", "用户名或密码错误")

    except Exception as e:
        print("登录出错:", e)
        messagebox.showerror("错误", "登录出错")

    finally:
        connect.close()


# 主界面
def mainpage():
    global window
    window = tk.Tk()
    window.title("超市信息管理系统")
    window.geometry('500x500')


    tk.Label(window, text="欢迎进入管理员界面", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(window, text="供应商管理", command=change_customer).pack(pady=10)
    button2 = tk.Button(window, text="员工管理", command=change_employee).pack(pady=10)
    button3 = tk.Button(window, text="商品管理", command=change_good).pack(pady=10)
    button4 = tk.Button(window, text="采购管理", command=change_buy).pack(pady=10)
    button5 = tk.Button(window, text="重新登录", command=change_login).pack(pady=10)

    # 计算窗口居中的位置
    window.update_idletasks()
    width = window.winfo_width()
    height = window.winfo_height()
    screenwidth = window.winfo_screenwidth()
    screenheight = window.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window.geometry('+{}+{}'.format(x, y))

    window.mainloop()

def employee_page():
    global window
    window = tk.Tk()
    window.title("超市信息管理系统")
    window.geometry('500x500')


    tk.Label(window, text="欢迎进入普通用户界面", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(window, text="查询个人信息", command=ygxx_page).pack(pady=10)
    button2 = tk.Button(window, text="查询商品信息", command=employee_select_good).pack(pady=10)
    button3 = tk.Button(window, text="查询采购信息", command=employee_to_select_buy).pack(pady=10)
    button4 = tk.Button(window, text="重新登录", command=change_login).pack(pady=10)

    # 计算窗口居中的位置
    window.update_idletasks()
    width = window.winfo_width()
    height = window.winfo_height()
    screenwidth = window.winfo_screenwidth()
    screenheight = window.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window.geometry('+{}+{}'.format(x, y))

    window.mainloop()

def employee_select_good():
    window.destroy()
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("商品信息")
    # 显示标题文字
    title_label = tk.Label(window_function, text="商品编号      商品名称  商品单价  供应商编号  商品简介      备注")
    title_label.grid(row=0, column=0, columnspan=6)
    # 窗口大小
    window_function.geometry('600x700')
    select_sp()
    button1 = tk.Button(window_function, text="返回", command=back_to_employee_page).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def employee_to_select_buy():
    window.destroy()
    employee_select_buy()

def back_to_employee_page():
    window_function.destroy()
    employee_page()

def employee_select_buy():
    global window_choice
    window_choice = tk.Tk()
    window_choice.title("采购管理界面")
    window_choice.geometry('400x500')
    button3 = tk.Button(window_choice, text="查询采购主表数据", command=employee_select_pay_main).pack(pady=10)
    button3 = tk.Button(window_choice, text="查询采购明细表数据", command=employee_select_pay_detail).pack(pady=10)
    button5 = tk.Button(window_choice, text="返回", command=back1_to_employee_page).pack(pady=10)

    # 计算窗口居中的位置
    window_choice.update_idletasks()
    width = window_choice.winfo_width()
    height = window_choice.winfo_height()
    screenwidth = window_choice.winfo_screenwidth()
    screenheight = window_choice.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_choice.geometry('+{}+{}'.format(x, y))

    window_choice.mainloop()

def back1_to_employee_page():
    window_choice.destroy()
    employee_page()

def back1_to_employee_select_buy():
    window_function.destroy()
    employee_select_buy()

def back2_to_employee_select_buy():
    window_function.destroy()
    employee_select_buy()

def employee_select_pay_main():  # 查询采购主表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("采购主表信息")
    # 显示标题文字
    title_label = tk.Label(window_function, text="采购清单号  员工编号  采购数量  采购总价  采购时间  备注")
    title_label.grid(row=0, column=0, columnspan=6)
    # 窗口大小
    window_function.geometry('600x700')
    select_cgzb()
    button1 = tk.Button(window_function, text="返回", command=back1_to_employee_select_buy).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def employee_select_pay_detail():  # 查询采购明细界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("采购明细信息")
    # 显示标题文字
    title_label = tk.Label(window_function, text="  采购明细号  采购清单号    商品编号    采购数量  商品单价  商品总价  备注")
    title_label.grid(row=0, column=0, columnspan=7)
    # 窗口大小
    window_function.geometry('600x700')
    select_cgmxb()
    button1 = tk.Button(window_function, text="返回", command=back2_to_employee_select_buy).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def display_employee_info(employee_id):
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    db_connection = connect
    cursor = db_connection.cursor()
    # *******************
    # 创建视图
    # cursor.execute("CREATE VIEW employee_info_view AS SELECT * FROM 员工表 WHERE 员工编号 = %s", (employee_id,))
    # *******************
    # 查询视图数据
    cursor.execute("SELECT * FROM 员工表 WHERE 员工编号 = %s", (employee_id,))
    employee_info = cursor.fetchall()

    db_connection.close()
    return employee_info


def on_button_click():
    yg_id = str(employee_id_entry.get())
    employee_info = display_employee_info(yg_id)
    if yg_id != ygbh:
        messagebox.showinfo("提示", "请输入与登录账号一致的员工编号！")
    else:
        messagebox.showinfo("提示", "验证成功！")
        for info in employee_info:
            result_text.insert(END,
                               f"员工编号: {info[0]}\n员工姓名: {info[1]}\n员工密码: {info[2]}\n员工级别: {info[3]}\n员工电话: {info[4]}\n员工工资: {info[5]}\n备注\n")

def ygxx_page():
    window.destroy()
    global window_function
    global yg_id, result_text, employee_id_entry
    window_function = Tk()
    window_function.title("员工个人信息查询")

    Label(window_function, text="我的员工编号:").pack()
    employee_id_entry = Entry(window_function)
    employee_id_entry.pack()

    # yg_id = str(employee_id_entry.get())

    query_button = Button(window_function, text="查询我的信息", command=on_button_click)
    query_button.pack()

    query_button2 = Button(window_function, text="返回", command=cx_back_to_employee_page)
    query_button2.pack(side=LEFT, padx=10, pady=10)

    result_text = Text(window_function, height=10, width=50)
    result_text.pack()

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def cx_back_to_employee_page():
    window_function.destroy()
    employee_page()

def export_customer_data( ):
    # 连接到MySQL数据库
    connection = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 查询表中的所有信息
    sql = "SELECT * FROM 供应商表"
    try:
        with connection.cursor() as cursor:
            # 执行SQL查询
            cursor.execute(sql)
            # 获取所有查询结果
            rows = cursor.fetchall()
            # 获取列标题（字段名）
            headers = [i[0] for i in cursor.description]
            # 打开CSV文件准备写入
            with open('D:\\python project\\SuperMarket\\供应商表.csv', 'w', newline='', encoding='utf-8') as csvfile:
                writer = csv.writer(csvfile)
                # 写入列标题
                writer.writerow(headers)
                # 写入查询结果
                writer.writerows(rows)
        connection.close()
        tk.messagebox.showinfo("提示", "数据导出成功")
    except Exception as e:
        tk.messagebox.showinfo("提示", "数据导出失败")

def export_employee_data( ):
    # 连接到MySQL数据库
    connection = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 查询表中的所有信息
    sql = "SELECT * FROM 员工表"
    try:
        with connection.cursor() as cursor:
            # 执行SQL查询
            cursor.execute(sql)
            # 获取所有查询结果
            rows = cursor.fetchall()
            # 获取列标题（字段名）
            headers = [i[0] for i in cursor.description]
            # 打开CSV文件准备写入
            with open('D:\\python project\\SuperMarket\\员工表.csv', 'w', newline='', encoding='utf-8') as csvfile:
                writer = csv.writer(csvfile)
                # 写入列标题
                writer.writerow(headers)
                # 写入查询结果
                writer.writerows(rows)
        connection.close()
        tk.messagebox.showinfo("提示", "数据导出成功")
    except Exception as e:
        tk.messagebox.showinfo("提示", "数据导出失败")

def export_good_data( ):
    # 连接到MySQL数据库
    connection = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 查询表中的所有信息
    sql = "SELECT * FROM 商品表"
    try:
        with connection.cursor() as cursor:
            # 执行SQL查询
            cursor.execute(sql)
            # 获取所有查询结果
            rows = cursor.fetchall()
            # 获取列标题（字段名）
            headers = [i[0] for i in cursor.description]
            # 打开CSV文件准备写入
            with open('D:\\python project\\SuperMarket\\商品表.csv', 'w', newline='', encoding='utf-8') as csvfile:
                writer = csv.writer(csvfile)
                # 写入列标题
                writer.writerow(headers)
                # 写入查询结果
                writer.writerows(rows)
        connection.close()
        tk.messagebox.showinfo("提示", "数据导出成功")
    except Exception as e:
        tk.messagebox.showinfo("提示", "数据导出失败")

def export_pay_main_data( ):
    # 连接到MySQL数据库
    connection = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 查询表中的所有信息
    sql = "SELECT * FROM 采购主表"
    try:
        with connection.cursor() as cursor:
            # 执行SQL查询
            cursor.execute(sql)
            # 获取所有查询结果
            rows = cursor.fetchall()
            # 获取列标题（字段名）
            headers = [i[0] for i in cursor.description]
            # 打开CSV文件准备写入
            with open('D:\\python project\\SuperMarket\\采购主表.csv', 'w', newline='', encoding='utf-8') as csvfile:
                writer = csv.writer(csvfile)
                # 写入列标题
                writer.writerow(headers)
                # 写入查询结果
                writer.writerows(rows)
        connection.close()
        tk.messagebox.showinfo("提示", "数据导出成功")
    except Exception as e:
        tk.messagebox.showinfo("提示", "数据导出失败")

def export_pay_detail_data( ):
    # 连接到MySQL数据库
    connection = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 查询表中的所有信息
    sql = "SELECT * FROM 采购明细表"
    try:
        with connection.cursor() as cursor:
            # 执行SQL查询
            cursor.execute(sql)
            # 获取所有查询结果
            rows = cursor.fetchall()
            # 获取列标题（字段名）
            headers = [i[0] for i in cursor.description]
            # 打开CSV文件准备写入
            with open('D:\\python project\\SuperMarket\\采购明细表.csv', 'w', newline='', encoding='utf-8') as csvfile:
                writer = csv.writer(csvfile)
                # 写入列标题
                writer.writerow(headers)
                # 写入查询结果
                writer.writerows(rows)
        connection.close()
        tk.messagebox.showinfo("提示", "数据导出成功")
    except Exception as e:
        tk.messagebox.showinfo("提示", "数据导出失败")



login_page()

